import { _decorator, Component, Node, Quat, Vec3 } from 'cc';
import { MenuManager } from './MenuManager';
const { ccclass, property } = _decorator;

@ccclass('BillboardSprite')
export class BillboardSprite extends Component {


    private _lookAtWorldPosition: Vec3 = new Vec3();
    private _rotation: Quat = new Quat();

    update(deltaTime: number) {
        if (!MenuManager.Instance.Camera) return;

        // 获取相机的世界位置
        MenuManager.Instance.Camera.node.getWorldPosition(this._lookAtWorldPosition);

        // 设置节点面向相机的方向
        this.node.lookAt(this._lookAtWorldPosition);

        // 保持自身的旋转，防止受父节点影响
        Quat.copy(this._rotation, this.node.worldRotation);
        this.node.setWorldRotation(this._rotation);
    }
}


